home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS04.ADF / text / consoleIO.txt < prev    next >
Text File  |  1985-12-04  |  57KB  |  1,979 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.                                   Chapter 1
  9.  
  10.  
  11.  
  12.                                Console Device
  13.  
  14.  
  15.  
  16.  
  17.       This chapter describes how you do console (keyboard  and  screen)
  18.       input  and  output on the Amiga.  The console device acts like an
  19.       enhanced ASCII terminal.  It obeys  many  of  the  standard  ANSI
  20.       sequences  as  well as additional special sequences unique to the
  21.       Amiga.
  22.  
  23.  
  24.       1.1.  INTRODUCTION
  25.  
  26.       Console I/O is tied closely to the Amiga Intuition  interface;  a
  27.       console  must  be  tied to a window that is already opened.  From
  28.       the Window data structure, the console device determines how many
  29.       characters it can display on a line and how many lines of text it
  30.       can display in a window without clipping at any edge.
  31.  
  32.       You can open the console device many times,  if  you  wish.   The
  33.       result  of  each  open  call is a new console unit.  AmigaDOS and
  34.       Intuition see to it that only one window is the currently  active
  35.       one,  and its console, if any, is the only one (with a few excep-
  36.       tions) that receives notification of input events, such as  keys-
  37.       trokes.   Later  in  this chapter you'll see that other Intuition
  38.       events can be sensed by the console device as well.
  39.  
  40.       NOTE:  For this entire chapter the characters  "<CSI>"  represent
  41.       the  Control  Sequence Introducer.  For output you may either use
  42.       the two-character sequence "<Esc>[" or  the  one-byte  value  $9B
  43.       (hex).  For input you will receive $9B's.
  44.  
  45.  
  46.       1.2.  SYSTEM FUNCTIONS
  47.  
  48.       The various system functions, such  as  DoIO(),  SendIO(),  Abor-
  49.       tIO(),  CheckIO()  and  so on operate normally.  The only caveats
  50.       are that the CMD_WRITE may cause the caller to  wait  internally,
  51.       even with SendIO(), and a task waiting on response from a console
  52.       is at the user's whim.  If a user never  reselects  that  window,
  53.       and the console response provides the only wakeup-call, that task
  54.       may well sleep indefinitely.
  55.  
  56.  
  57.  
  58.                               November 17, 1985
  59.  
  60.  
  61.  
  62.  
  63.  
  64.                                     - 2 -
  65.  
  66.  
  67.       1.3.  CONSOLE I/O
  68.  
  69.       The console device may be thought of as a  kind  of  a  terminal.
  70.       You  send  a  character  stream  to the console device.  You also
  71.       receive a  character  stream  from  the  console  device.   These
  72.       streams may be characters or special sequences.
  73.  
  74.  
  75.       Console character screen output (as compared to  console  command
  76.       sequence  transmission) outputs all standard printable characters
  77.       (character values hex 20 thru 7E and A0 thru FF) normally.   Many
  78.       control  characters  such  as BACKSPACE and RETURN are translated
  79.       into their exact ANSI equivalent actions.  The line-feed  charac-
  80.       ter  is a bit different, in that it can be translated into a new-
  81.       line character.  The net effect is that the cursor moves  to  the
  82.       first column of the next line whenever a <LF> is displayed.  This
  83.       is set via the mode control sequences  discussed  under  "Control
  84.       Sequences for Screen Output".
  85.  
  86.  
  87.       If you read from the console  device,  the  keyboard  inputs  are
  88.       preprocessed  for you.  You will get the ASCII characters such as
  89.       "B".  Most normal text gathering programs will read from the con-
  90.       sole  device  in this manner.  Special programs like word proces-
  91.       sors and music keyboard programs will use raw  input.   Keys  are
  92.       converted via the keymap associated with the unit.
  93.  
  94.       The sections below deal with the following topics:
  95.  
  96.           o   Setting up for  console  I/O  (creating  an  I/O  request
  97.               structure)
  98.  
  99.           o   Writing to the console to control its behavior
  100.  
  101.           o   Reading from the console
  102.  
  103.           o   Closing down a console device
  104.  
  105.       This section shows you how to set up for console I/O.
  106.  
  107.  
  108.       1.4.  CREATING AN I/O REQUEST
  109.  
  110.       Console I/O, like other devices, requires that you create an  I/O
  111.       request  message that you pass to the console device for process-
  112.       ing.  The message contains the command, as well as a  data  area.
  113.       In  the  data  area,  for a write, there will be a pointer to the
  114.       stream of information you wish to write to the  console.   For  a
  115.       read,  this  data  pointer shows where the console is to copy the
  116.       data it has for you.  There is also a length field that says  how
  117.       many  characters (maximum) are to be copied either from or to the
  118.       console device.
  119.  
  120.  
  121.  
  122.  
  123.                               November 17, 1985
  124.  
  125.  
  126.  
  127.  
  128.  
  129.                                     - 3 -
  130.  
  131.  
  132.       Here is a program fragment that can be used to create the message
  133.       block that you use for console communications.
  134.  
  135.       For writing to the console:
  136.  
  137.               struct IOStdReq *consoleWriteMsg;       /* I/O request block pointer */
  138.               struct Port *consoleWritePort;          /* a port at which to receive replies*/
  139.  
  140.               consoleWritePort = CreatePort("mycon.write",0);
  141.               if(consoleWritePort == 0) exit(100);    /* error in createport */
  142.               consoleWriteMsg =  CreateStdIO(consoleWritePort);
  143.               if(consoleWriteMsg == 0) exit(200);     /* error in createstdio */
  144.  
  145.  
  146.       For reading from the console:
  147.  
  148.               struct IOStdReq *consoleReadMsg;        
  149.                         /* I/O request block pointer */
  150.               struct Port *consoleReadPort;           
  151.                         /* a port at which to receive replies */
  152.  
  153.               consoleReadPort = CreatePort("mycon.read",0);
  154.               if(consoleReadPort == 0) exit(300);     /* error in createport */
  155.               consoleReadMsg =  CreateStdIO(consoleReadPort);
  156.               if(consoleReadMsg == 0) exit(400);      /* error in createstdio */
  157.  
  158.  
  159.       These fragments show two messages and ports being  set  up.   You
  160.       would  use  this  if you want to have a read command continuously
  161.       queued up while using a separate message with its associated port
  162.       to send control command sequences to the console.
  163.  
  164.       In addition, if you want to queue up  multiple  commands  to  the
  165.       console,  you  may wish to create multiple messages (but probably
  166.       just one port for receiving replied messages from the device).
  167.  
  168.  
  169.       1.5.  OPENING A CONSOLE DEVICE
  170.  
  171.       For other devices, you normally use OpenDevice() to pass an unin-
  172.       itialized  IORequest  block to the device.  For a console device,
  173.       this is slightly different.  You must have initialized two fields
  174.       in  the  request  block;  namely, the data pointer and the length
  175.       field.  Here is a subroutine that can be used to open  a  console
  176.       device  (attach  it  to  an  existing  window).   It assumes that
  177.       intuition.library is already open, a window has also been opened,
  178.       and this new console is to be attached to the open window.
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.                               November 17, 1985
  191.  
  192.  
  193.  
  194.  
  195.  
  196.                                     - 4 -
  197.  
  198.  
  199.  
  200.               /* this function returns a value of 0 if the console
  201.                * device opened correctly and a nonzero value (the error
  202.                * returned from OpenDevice) if there was an error.
  203.                */
  204.               OpenConsole(request,window)
  205.               struct IOStdReq *request;
  206.               struct Window *window;
  207.               {
  208.               /* Open a console device */
  209.  
  210.                       request->io_Data = (char *) window;
  211.                       request->io_Length = sizeof(*window);
  212.                       return(OpenDevice("console.device", 0, request, 0));
  213.               }
  214.  
  215.  
  216.  
  217.       To perform console I/O, you fill in fields  of  the  console  I/O
  218.       standard request, and pass this block to the console device using
  219.       one of the normal I/O functions.  When  the  console  device  has
  220.       completed the action, the device returns the message block to the
  221.       port you have designated within the message itself.  The function
  222.       CreateStdIO()  initializes  the message to contain the address of
  223.       the ReplyPort.
  224.  
  225.       Here are subroutines that uses the IOStdReq created  above.  Note
  226.       that  the  IOStdReq  itself contains a pointer to the device with
  227.       which it is communicating so a single function  can  be  used  to
  228.       communicate with multiple consoles.
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.                               November 17, 1985
  257.  
  258.  
  259.  
  260.  
  261.  
  262.                                     - 5 -
  263.  
  264.  
  265.  
  266.               /* output a single character to a specified console */
  267.  
  268.               ConPutChar(request,character)
  269.               struct IOStdReq *request;
  270.               char character;
  271.               {
  272.                       request->io_Command = CMD_WRITE;
  273.                       request->io_Data = &character;
  274.                       request->io_Length = 1;
  275.                       DoIO(request);
  276.                       return;
  277.               }
  278.  
  279.               /* output a stream of known length to a console */
  280.  
  281.               ConWrite(request,string,length)
  282.               struct IOStdReq *request;
  283.               char *string;
  284.               int length;
  285.               {
  286.                       request->io_Command = CMD_WRITE;
  287.                       request->io_Data = string;
  288.                       request->io_Length = length;
  289.                       DoIO(request);
  290.                       return;
  291.               }
  292.  
  293.               /* output a NULL-terminated string of characters to a console */
  294.  
  295.               ConPutStr(request,string)
  296.               struct IOStdReq *request;
  297.               char *string;
  298.               {
  299.               request->io_Command = CMD_WRITE;
  300.               request->io_Data = string;
  301.               request->io_Length = -1;        /* tells console to end when it
  302.                                               * sees a terminating zero on
  303.                                               * the string. */
  304.               DoIO(request);
  305.                       return;
  306.               }
  307.  
  308.  
  309.  
  310.       1.6.  CONTROL SEQUENCES FOR SCREEN OUTPUT
  311.  
  312.       Here is a list of the functions that the console device supports,
  313.       along with the character stream that you must send to the console
  314.       to produce the effect.  Where the function table indicates multi-
  315.       ple  characters, it is more efficient to use the ConWrite() func-
  316.       tion rather than ConPutChar() since it  avoids  the  overhead  of
  317.       transfering  the  message  block multiple times.  The table below
  318.       uses the second form of <CSI>, that is,  the  hex  value  9B,  to
  319.  
  320.  
  321.                               November 17, 1985
  322.  
  323.  
  324.  
  325.  
  326.  
  327.                                     - 6 -
  328.  
  329.  
  330.       minimize  the number of characters to be transmitted to produce a
  331.       function.
  332.  
  333.       In the table below, if an item is enclosed in square brackets, it
  334.       is  an optional item and may be omitted.  For example, for INSERT
  335.       [N] CHARACTERS, the value for N or M is shown as  optional.   The
  336.       console  device  responds  to such optional items by treating the
  337.       value of N as if it is not specified.
  338.  
  339.       The value of N or M is always a decimal  number,  having  one  or
  340.       more ASCII digits to express its value.
  341.  
  342.  
  343.                     Table 1-1: Console Control Sequences
  344.  
  345.  
  346.  
  347.       COMMAND SEQUENCE OF         CHARACTERS         (in hexadecimal)
  348.  
  349.     BACKSPACE (move left one column)            08 
  350.     LINE FEED  (move down one text line         0A
  351.                 as specified by the mode
  352.                 function below) 
  353.     VERTICAL TAB (move up one text  line)       0B
  354.     FORM FEED (clear the console's screen)      0C 
  355.     CARRIAGE RETURN (move to first column)      0D 
  356.     SHIFT IN   (undo SHIFT OUT)                 OE 
  357.     SHIFT OUT  (set MSB of each character       0F
  358.                 before displaying)
  359.     ESC (escape; can be part of the control     1B
  360.                 sequence introducer) 
  361.     CSI (control sequence introducer)           ESC [
  362.     RESET TO INITIAL STATE                      9B 63
  363.     INSERT [N] CHARACTERS                       9B [N] 40
  364.         (Inserts one or more spaces, shifting the
  365.                 remainder of the line to the right.) 
  366.     CURSOR UP [N]  CHARACTER POSITIONS          9B [N] 41
  367.            (default = 1) 
  368.     CURSOR DOWN [N] CHARACTER POSITIONS         9B [N] 42
  369.            (default = 1) 
  370.     CURSOR FORWARD [N] CHARACTER POSITIONS      9B [N] 43
  371.            (default = 1) 
  372.     CURSOR BACKWARD [N] CHARACTER               9B [N] 44
  373.            POSITIONS (default = 1) 
  374.     CURSOR NEXT LINE  [N]  (to column 1)        9B [N] 45 
  375.     CURSOR PRECEDING LINE [N]                   9B [N] 46
  376.            (to column 1) 
  377.     MOVE CURSOR TO ROW; COLUMN                  9B [N] [3B  N] 48
  378.            where N is row, M is column, and
  379.            semicolon (hex 3B) must be present
  380.            as a separator, or if row is left
  381.            out, so the console device can tell
  382.            that the number after the semicolon
  383.            actually represents the column  number.
  384.     ERASE TO END OF DISPLAY                     9B 4A
  385.     ERASE TO END OF LINE                        9B 4B
  386.  
  387.  
  388.  
  389.                               November 17, 1985
  390.  
  391.  
  392.  
  393.  
  394.  
  395.                                     - 7 -
  396.  
  397.  
  398.     INSERT LINE (above the line containing      9B 4C
  399.                 the cursor) 
  400.     DELETE LINE (remove current line, move      9B 4D
  401.                 all lines up one position to fill
  402.                 gap, blank bottom line) 
  403.     DELETE CHARACTER [N] (that cursor is        9B [N] 50
  404.            sitting on and to the right if
  405.            [N] is  specified)
  406.     SCROLL UP [N] LINES (Remove line(s) from    9B [N] 53
  407.            top of screen, move all other lines
  408.            down, blanks [N]  bottom  lines).
  409.     SCROLL  DOWN  [N]  LINES (Remove line(s)    9B [N] 54
  410.            from bottom of screen, move all
  411.            other lines up, blanks [N]  top  lines).   
  412.     SET MODE (cause LINEFEED to respond as      9B 32 30 68
  413.             RETURN-LINEFEED) 
  414.     RESET MODE (cause LINEFEED to respond       9B 32 30 6C
  415.             only as LINEFEED) 
  416.     DEVICE STATUS REPORT (cause console to      9B 6E
  417.            insert into your read-stream a CURSOR
  418.            POSITION REPORT; see "Reading from
  419.            the  Console"  for  more  info).
  420.     SELECT GRAPHIC RENDITION See note below.    [S];[F];[B]
  421.            (select text style, foreground color,
  422.            background color)
  423.  
  424.     NOTE:  For SELECT GRAPHIC RENDITION, any number of
  425.            parameters, in any order, are valid.  They are
  426.            separated by semicolons.
  427.  
  428.                    <style> =
  429.                            0       plain text
  430.                            1       bold-face
  431.                            3       italic
  432.                            4       underscore
  433.                            7       inverse-video
  434.  
  435.                    <fg> =
  436.                            30 - 37 selecting system colors 0-7 for foreground
  437.                                    transmitted as two ASCII characters
  438.  
  439.                    <bg> =
  440.                            40 - 47 selecting system colors 0-7 for background
  441.                                    transmitted as two ASCII characters
  442.  
  443.  
  444.            For example,  to select  bold-face,  with  color  3  as
  445.            foreground   and   color  0  as  background,  send  the
  446.            sequence:
  447.  
  448.                    9B 31 3B 33 33 3B 34 30 6D
  449.  
  450.  
  451.  
  452.  
  453.                               November 17, 1985
  454.  
  455.  
  456.  
  457.  
  458.  
  459.                                     - 8 -
  460.  
  461.  
  462.            representing the ASCII sequence:
  463.  
  464.                    "<CSI>1;33;40m"
  465.  
  466.  
  467.            where <CSI> is the control  sequence  introducer,  here
  468.            used as the single-character value 9B hex.
  469.  
  470.            The following are not ANSI standard sequences; they are
  471.            private Amiga sequences.
  472.  
  473.            In the four command descriptions that  follow,  length,
  474.            width,  and  offset  are comprised of one or more ASCII
  475.            digits, defining a decimal value.
  476.  
  477.  
  478.            COMMAND SEQUENCE OF CHARACTERS  (in hexadecimal)
  479.  
  480.            SET PAGE LENGTH (in character raster lines,
  481.                 causes console to recalculate,
  482.                 using current font, how many text       9B <length> 74
  483.                 lines will fit on the page.
  484.            SET LINE LENGTH (in character positions,
  485.                 using current font, how many characters
  486.                 should be placed on each line).         9B <width> 75
  487.            SET LEFT OFFSET (in raster columns, how far
  488.                 from the left of the window
  489.                 should the text begin).                 9B <offset> 78
  490.            SET TOP OFFSET (in raster lines, how far
  491.                 from the top of the window's
  492.                 RastPort should the topmost
  493.                 line of the character begin).           9B <offset> 79
  494.  
  495.  
  496.            NOTE:   The console normally  handles  the  above  four
  497.            functions  automatically.   To  allow it to do so again
  498.            after setting your own values, you can send the func-
  499.            tion without a parameter.
  500.  
  501.  
  502.            COMMAND SEQUENCE OF CHARACTERS  (in hexadecimal)
  503.            
  504.            SET RAW EVENTS-see the separate topic
  505.                 "Selecting Raw Input Events"
  506.                 below for more details.
  507.            RESET RAW EVENTS-see "Selecting Raw Input Events" below.
  508.  
  509.  
  510.  
  511.                               November 17, 1985
  512.  
  513.  
  514.  
  515.  
  516.  
  517.                                     - 9 -
  518.  
  519.  
  520.            SET CURSOR RENDITION - make the cursor
  521.                 visible or invisible:
  522.                      invisible:    9B 30 70
  523.                      visible:      9B 70
  524.            WINDOW STATUS REQUEST - ask the console
  525.                 device to tell you the current
  526.                 bounds of the window, in
  527.                 upper and lower row and column
  528.                 character positions.
  529.                 (User may have resized or repositioned
  530.                 it).  See "Window Bounds Report" below.    9B 71
  531.  
  532.  
  533.  
  534.  
  535.                                   Examples
  536.  
  537.       Move cursor right by 1:
  538.  
  539.               Character string equivalents:   <CSI>C or <CSI>1C
  540.               Numeric (hex) equivalents:      9B 43 9B 31 43
  541.  
  542.  
  543.       Move cursor right by 20:
  544.  
  545.               Character string equivalent:    <CSI>20C
  546.               Numeric (hex) equivalent:       9B 32 30 43
  547.  
  548.  
  549.       Move cursor to upper left corner (home):
  550.  
  551.               Character string equivalents:
  552.                       <CSI>H  or
  553.                       <CSI>1;1H or
  554.                       <CSI>;1H or
  555.                       <CSI>1;H
  556.  
  557.               Numeric (hex) equivalents:
  558.                        9B 48
  559.                        9B 31 3B 31 48
  560.                        9B 3B 31 48
  561.                        9B 31 3B 48
  562.  
  563.  
  564.       Move cursor to the forth column of the first line of the window:
  565.  
  566.  
  567.  
  568.  
  569.  
  570.  
  571.  
  572.  
  573.                               November 17, 1985
  574.  
  575.  
  576.  
  577.  
  578.  
  579.                                    - 10 -
  580.  
  581.  
  582.  
  583.               Character string equivalents:
  584.                       <CSI>1;4H or
  585.                       <CSI>;4H
  586.  
  587.               Numeric (hex) equivalents:
  588.                        9B 31 3B 34 48
  589.                        9B 3B 34 48
  590.  
  591.  
  592.       Clear the screen:
  593.  
  594.               Character string equivalents:
  595.                       <FF> or CTRL-L  {clear screen character} or
  596.                       <CSI>H<CSI>J    {home and clear to end of screen} or
  597.  
  598.               Numeric (hex) equivalents:
  599.                        0C
  600.                        9B 48 9B 4A
  601.  
  602.  
  603.  
  604.       Reading input from the console device returns an ANSI 3.64  stan-
  605.       dard  byte  stream.   This  stream  may contain normal characters
  606.       and/or RAW input event information.  You may also  request  other
  607.       RAW  input  events  using the SET RAW EVENTS and RESET RAW EVENTS
  608.       control sequences discussed below.  See "Selection of  Raw  Input
  609.       Events".
  610.  
  611.       The following subroutines are useful for setting up  for  console
  612.       reads.  Only a single-character-at-a-time version is shown here.
  613.  
  614.       NOTE:  This example does not illustrate the fact that  a  request
  615.       for  more  than  one character can be satisfied by only one, thus
  616.       requiring you to look at io_actual.
  617.  
  618.  
  619.  
  620.            /* queue up a read request to a console, show where to
  621.             * put the character when ready to be returned.  Most
  622.             * efficient if this is called right after console is
  623.             * opened */
  624.  
  625.            QueueRead(request,whereto)
  626.            struct IOStdReq *request;
  627.            char *whereto;
  628.            {
  629.                    request->io_Command = CMD_READ;
  630.                    request->io_Data = whereto;
  631.                    request->io_Length = 1;
  632.                    SendIO(request);
  633.                    return;
  634.            }
  635.  
  636.  
  637.  
  638.  
  639.                               November 17, 1985
  640.  
  641.  
  642.  
  643.  
  644.  
  645.                                    - 11 -
  646.  
  647.  
  648.            /* see if there is a character to read.  If none, don't wait,
  649.             * come back with a value of -1 */
  650.            int
  651.            ConMayGetChar(consolePort,request,whereto)
  652.            struct Port *consolePort
  653.            struct IOStdReq *request;
  654.            char *whereto;
  655.            {
  656.                    register temp;
  657.  
  658.                    if ( GetMsg(consolePort) == NULL ) return(-1);
  659.                    temp = *whereto;
  660.                    QueueRead(request,whereto);
  661.                    return(temp);
  662.            }
  663.  
  664.            /* go and get a character; put the task to sleep if
  665.             * there isn't one present */
  666.  
  667.            UBYTE
  668.            ConGetChar(consolePort,request,whereto)
  669.            struct IOStdReq *request;
  670.            struct Port *consolePort;
  671.            char *whereto;
  672.            {
  673.                    register temp;
  674.                    while((GetMsg(consolePort) == NULL)) WaitPort(consolePort);
  675.                    temp = *whereto;        /* get the character */
  676.                    QueueRead(request,whereto);
  677.                    return(temp);
  678.            }
  679.  
  680.  
  681.  
  682.       For the most part, keys whose keycaps are labeled with ANSI stan-
  683.       dard  characters  will  ordinarily be translated into their ASCII
  684.       equivalent character by the console device through the use of its
  685.       keymap.  A separate section in this chapter has been dedicated to
  686.       the method used to establish a keymap and the internal  organiza-
  687.       tion of the keymap.
  688.  
  689.       For keys other than  those  with  normal  ASCII  equivalents,  an
  690.       escape sequence is generated and inserted into your input stream.
  691.       For example, in the default state (no raw input events  selected)
  692.       the function and arrow keys will cause the following sequences to
  693.       be inserted in the input stream:
  694.  
  695.  
  696.  
  697.  
  698.  
  699.  
  700.  
  701.  
  702.  
  703.  
  704.  
  705.                               November 17, 1985
  706.  
  707.  
  708.  
  709.  
  710.  
  711.                                    - 12 -
  712.  
  713.  
  714.  
  715.                    Table 1-2: Special Key Report Sequences
  716.  
  717.  
  718.       center box; c c l.
  719.       KEY     UNSHIFTED SENDS SHIFTED SENDS
  720.  
  721.       F1      <CSI>0~ <CSI>10~                 F2      <CSI>1~ <CSI>11~
  722.       F3      <CSI>2~ <CSI>12~                 F4      <CSI>3~ <CSI>13~
  723.       F5      <CSI>4~ <CSI>14~                 F6      <CSI>5~ <CSI>15~
  724.       F7      <CSI>6~ <CSI>16~                 F8      <CSI>7~ <CSI>17~
  725.       F9      <CSI>8~ <CSI>18~                 F10     <CSI>9~ <CSI>19~
  726.       HELP    <CSI>?~ <CSI>?~  (same)
  727.  
  728.       Arrow keys:
  729.  
  730.       Up      <CSI>A  <CSI>T~                   Down    <CSI>B  <CSI>S~
  731.       Left    <CSI>C  <CSI> A~ (notice the space)
  732.       Right   <CSI>D  <CSI> @~ (notice the space)
  733.  
  734.  
  735.  
  736.       If you have sent the DEVICE STATUS REPORT command  sequence,  the
  737.       console  device  returns a cursor position report into your input
  738.       stream.  It takes the form:
  739.  
  740.               <CSI><row>;<column>R
  741.  
  742.       For example, if the cursor is at column 40, and row 12, here  are
  743.       the ASCII values you receive in a stream:
  744.  
  745.               9B 34 30 3B 31 32 52
  746.  
  747.  
  748.  
  749.       A user may have either moved or resized the window to which  your
  750.       console  is bound.  By issuing a WINDOW STATUS REPORT to the con-
  751.       sole, you can read the current position and  size  in  the  input
  752.       stream.  This window bounds report takes the following form:
  753.  
  754.               <CSI>1;1;<bottom margin>;<right margin>r
  755.  
  756.  
  757.       Note that the top and left margins are always 11 for  the  Amiga.
  758.       The  bottom  and right margins give you the window row and column
  759.       dimensions as well.  For a window that holds  20  lines  with  60
  760.       characters  per line, you will receive the following in the input
  761.       stream:
  762.  
  763.               9B 31 3B 31 3B 32 30 3B 36 30 73
  764.  
  765.  
  766.  
  767.  
  768.  
  769.                               November 17, 1985
  770.  
  771.  
  772.  
  773.  
  774.  
  775.                                    - 13 -
  776.  
  777.  
  778.       If the keyboard information, including "cooked"  keystrokes  does
  779.       not  give  you  enough  information  about  input  events you can
  780.       request additional information from the console driver.
  781.  
  782.       The command to SET RAW EVENTS is formatted as:
  783.  
  784.               "<CSI>[event-types-separated-by-semicolons]{"
  785.  
  786.  
  787.       If, for example, you need to know when each key  is  pressed  and
  788.       released you would request "RAW keyboard input".  This is done by
  789.       writing "<CSI>1{" to the console.  In a  single  SET  RAW  EVENTS
  790.       request,  you  can  ask  the  console to setup for multiple event
  791.       types at one time.  You must send  multiple  numeric  parameters,
  792.       separating  them  by  semicolons  (;).   Example:  ask for gadget
  793.       pressed, gadget released and  close  gadget  events   -    write:
  794.       "<CSI>7;8;11{" (all as ASCII characters, without the quotes).
  795.  
  796.       You can reset, that is, delete from reporting, one or more of the
  797.       raw  input  event types by using the RESET RAW EVENTS command, in
  798.       the same manner as the SET RAW EVENTS was used to establish  them
  799.       in the first place.  This command stream is formatted as:
  800.  
  801.               <CSI>[event-types-separated-by-semicolons]}
  802.  
  803.  
  804.       So, for example, you could reset all of the  events  set  in  the
  805.       above    example    by   transmitting   the   command   sequence:
  806.       "<CSI>7;8;11}" Here is a list of the valid raw input event types:
  807.  
  808.  
  809.                       Table 1-3: Raw Input Event Types
  810.  
  811.  
  812.       REQUEST NUMBER  DESCRIPTION
  813.  
  814.     0       nop     Used internally.
  815.     1       RAW     keyboard input. Intuition swallows all by the select
  816.                     button.  
  817.     2       RAW mouse input  
  818.     3       Event Sent whenever your window is made active.  
  819.     4       Pointer position  
  820.     5       (unused)  
  821.     6       Timer  
  822.     7       Gadget pressed
  823.     8       Gadget released  
  824.     9       Requester activity 
  825.     10      Menu numbers 
  826.     11      Close Gadget 
  827.     12      Window resized  
  828.     13      Window refreshed 
  829.     14      Preferences changed (not yet implemented) 
  830.     15      Disk removed 
  831.     16      Disk inserted
  832.  
  833.  
  834.  
  835.  
  836.  
  837.  
  838.  
  839.  
  840.  
  841.                               November 17, 1985
  842.  
  843.  
  844.  
  845.  
  846.  
  847.                                    - 14 -
  848.  
  849.  
  850.       1.7.  COMPLEX INPUT EVENT REPORTS
  851.  
  852.       If you select any of these events you will start to get  informa-
  853.       tion about the events in the following form:
  854.  
  855.               <CSI><class>;<subclass>;<keycode>;<qualifiers>;<x>;<y>;
  856.               <seconds>;<microseconds>|
  857.  
  858.  
  859.       where:
  860.  
  861.       <CSI>
  862.           is a one-byte field.  It  is  the  "control  sequence  intro-
  863.           ducer", 9B in hex.
  864.  
  865.       <class>
  866.           is the RAW input event type, from the above table.
  867.  
  868.       <subclass>
  869.           is usually 0.  If the mouse is moved to the right controller,
  870.           this would be 1.
  871.  
  872.       <keycode>
  873.           indicates which key number was pressed (see  figure  4-1  and
  874.           table  4-5).   This field can also be used for mouse informa-
  875.           tion.
  876.  
  877.       <qualifiers>
  878.           indicates the state of the keyboard and system.  The  qualif-
  879.           iers are defined as follows:
  880.  
  881.  
  882.  
  883.  
  884.  
  885.  
  886.  
  887.  
  888.  
  889.  
  890.  
  891.  
  892.  
  893.  
  894.  
  895.  
  896.  
  897.  
  898.  
  899.  
  900.  
  901.  
  902.  
  903.  
  904.  
  905.  
  906.                               November 17, 1985
  907.  
  908.  
  909.  
  910.  
  911.  
  912.                                    - 15 -
  913.  
  914.  
  915.  
  916.                         Table 1-4: Input Event Qualifiers
  917.  
  918.  
  919.           BIT     MASK    KEY
  920.  
  921.         0       0001    left   shift   
  922.         1       0002    right    shift
  923.         2       0004    capslock  *Associated keycode is
  924.                                   special; see below.
  925.         3       0008    control        
  926.         4       0010    left ALT
  927.         5       0020    right  ALT
  928.         6       0040    left Amiga key pressed
  929.         7       0080    right Amiga key pressed
  930.         8       0100    numeric pad       
  931.         9       0200    repeat
  932.         10      0400    interrupt  Not currently used.
  933.         11      0800    multi broadcast  This window (active one)
  934.                                   or all windows.
  935.         12      1000    left mouse button    
  936.         13      2000    right mouse button
  937.         14      4000    middle mouse button  (Not available on
  938.                                             standard  mouse.)  
  939.         15      8000    relative mouse  Indicates mouse coordinates
  940.                                         are relative, not absolute.
  941.  
  942.  
  943.       The CAPS LOCK key is handled in a special manner.  It  only  gen-
  944.       erates  a  keycode  when  it is pressed, not when it is released.
  945.       However the up/down bit (80 hex) is still used and reported.   If
  946.       pressing  the caps lock key causes the LED to light then key code
  947.       62 (caps lock pressed) is sent.  If pressing the  caps  lock  key
  948.       extinguishes  the  LED  then key code 190 (caps lock released) is
  949.       sent.  In effect, the keyboard reports  this  key  as  held  down
  950.       until it is struck again.
  951.  
  952.       The <x> and <y> fields are filled by some classes with an  Intui-
  953.       tion address:  x<<16+y.
  954.  
  955.       The <seconds> and <microseconds> fields contain the  system  time
  956.       stamp  taken  at  the  time the event occurred.  These values are
  957.       stored as long-words by the system.
  958.  
  959.       With RAW keyboard input selected, keys will no  longer  return  a
  960.       simple  one-character  "A" to "Z" but will rather return raw key-
  961.       code reports of the form:
  962.  
  963.               <CSI>1;0;<keycode>;<qualifiers>;0;0;<seconds>;<microseconds>|
  964.  
  965.  
  966.       For example, if the user pressed and released the  "B"  key  with
  967.       the  left  shift  and  right  Amiga  keys  also pressed you might
  968.       receive the following data:
  969.  
  970.  
  971.  
  972.  
  973.  
  974.                               November 17, 1985
  975.  
  976.  
  977.  
  978.  
  979.  
  980.                                    - 16 -
  981.  
  982.  
  983.  
  984.               <CSI>1;0;35;129;0;0;23987;99|
  985.               <CSI>1;0;163;129;0;0;24003;18|
  986.  
  987.  
  988.       The <keycode> field is an ASCII decimal  value  representing  the
  989.       key pressed or released.  Adding 128 to the pressed key code will
  990.       result in the released keycode.   Figure  4-1  lets  you  convert
  991.       quickly  from  a  key  to its keycode. The tables let you convert
  992.       quickly from a keycode to a key.
  993.  
  994.  
  995.  
  996.  
  997.  
  998.  
  999.  
  1000.  
  1001.  
  1002.  
  1003.  
  1004.  
  1005.  
  1006.  
  1007.  
  1008.  
  1009.  
  1010.  
  1011.  
  1012.  
  1013.  
  1014.  
  1015.  
  1016.  
  1017.  
  1018.            Figure 1-1: The Amiga Keyboard, Showing Keycodes in Hex
  1019.  
  1020.  
  1021.       The default values given correspond to:
  1022.  
  1023.           1)  The values the console device will return when these keys
  1024.               are pressed, and
  1025.  
  1026.           2)  The Keycaps as shipped with the  standard  American  key-
  1027.               board.
  1028.  
  1029.  
  1030.  
  1031.  
  1032.  
  1033.  
  1034.  
  1035.  
  1036.  
  1037.  
  1038.  
  1039.  
  1040.                               November 17, 1985
  1041.  
  1042.  
  1043.  
  1044.  
  1045.  
  1046.                                    - 17 -
  1047.  
  1048.  
  1049.                   Table 1-5: System Default Console Key Mapping
  1050.  
  1051.  
  1052.         RAW     UNSHIFTED       SHIFTED
  1053.         KEY     KEYCAP  DEFAULT DEFAULT NUMBER  LEGEND  VALUE   VALUE
  1054.  
  1055.         00      ` ~     ` (Accent grave)        ~  (tilde)  
  1056.         01      1    !     1       !     
  1057.         02      2    @     2       @    
  1058.         03      3    #     3       #    
  1059.         04      4    $     4       $     
  1060.         05      5    %     5       %     
  1061.         06      6    ^     6       ^    
  1062.         07      7    &     7       &    
  1063.         08      8    *     8       *     
  1064.         09      9    (     9       (  
  1065.         0A      0  )     0       ) 
  1066.         0B      - _     -          (Hyphen)      _   (Underscore)   
  1067.         0C      =    +     =       +
  1068.         0D      \\     |    \\      |
  1069.         0E       (undefined)
  1070.         0F      0       0       0 (Numeric pad)
  1071.  
  1072.         10      Q       q       Q           
  1073.         11      W       w       W
  1074.         12      E       e       E           
  1075.         13      R       r       R
  1076.         14      T       t       T           
  1077.         15      Y       y       Y
  1078.         16      U       u       U           
  1079.         17      I       i       I
  1080.         18      O       o       O 
  1081.         19      P       p       P 
  1082.         1A      [{     [       {           
  1083.         1B      ]           }     ]       }
  1084.         1C              (undefined)         
  1085.         1D      1       1       1  (Numeric pad)   
  1086.         1E      2       2       2   (Numeric   pad)
  1087.         1F      3       3       3 (Numeric pad)
  1088.  
  1089.         20      A       a       A           21      S       s       S
  1090.         22      D       d       D           23      F       f       F
  1091.         24      G       g       G           25      H       h       H
  1092.         26      J       j       J           27      K       k       K
  1093.         28      L       l       L 
  1094.         29      ; :     ;       : 
  1095.         2A      '       "     ' (single quote)    "
  1096.         2B              (RESERVED)      (RESERVED)
  1097.         2C              (undefined)         
  1098.         2D      4       4       4  (Numeric pad)   
  1099.         2E      5       5       5   (Numeric   pad)
  1100.         2F      6       6       6 (Numeric pad)
  1101.  
  1102.         30              (RESERVED)      (RESERVED)
  1103.         31      Z       z       Z           
  1104.         32      X       x       X
  1105.         33      C       c       C           
  1106.         34      V       v       V
  1107.         35      B       b       B           
  1108.         36      N       n       N
  1109.         37      M       m       M 
  1110.         38      ,  <     ,  (comma)       <
  1111.         39      .  >     .  (period)      > 
  1112.         3A      / ?     /       ?
  1113.         3B              (undefined)         
  1114.         3C      .       .       . (Numeric pad)   
  1115.         3D      7       7       7 (Numeric pad)
  1116.         3E      8       8       8 (Numeric pad)
  1117.         3F      9       9       9 (Numeric pad)
  1118.  
  1119.         40      (Space        bar)     20      20        
  1120.         41      BACKSPACE      08      08              
  1121.         42      TAB     09      09
  1122.         43      ENTER   0D      0D   (Numeric pad)
  1123.         44      RETURN  0D      0D         
  1124.         45      ESC     1B      1B
  1125.         46      DEL     7F      7F        
  1126.         47              (undefined)
  1127.  
  1128.  
  1129.  
  1130.                               November 17, 1985
  1131.  
  1132.  
  1133.  
  1134.  
  1135.  
  1136.                                    - 18 -
  1137.  
  1138.             
  1139.         48              (undefined)       
  1140.         49              (undefined)
  1141.         4A      -       -       -  (Numeric Pad)
  1142.         4B              (undefined)                        
  1143.         4C      Up Arrow        <CSI>A~ <CSI>T~                     
  1144.         4D      Down Arrow      <CSI>B~ <CSI>S~                    
  1145.         4E      Forward Arrow   <CSI>C~ <CSI> A~         [1]         
  1146.         4F      Backward Arrow  <CSI>D~ <CSI> @~
  1147.  
  1148.  
  1149.  
  1150.  
  1151.  
  1152.  
  1153.  
  1154.  
  1155.  
  1156.  
  1157.  
  1158.  
  1159.  
  1160.  
  1161.  
  1162.  
  1163.  
  1164.  
  1165.  
  1166.  
  1167.  
  1168.  
  1169.  
  1170.  
  1171.  
  1172.  
  1173.  
  1174.  
  1175.  
  1176.  
  1177.  
  1178.  
  1179.  
  1180.  
  1181.  
  1182.  
  1183.  
  1184.  
  1185.  
  1186.  
  1187.  
  1188.  
  1189.       _________________________
  1190.         [1] In shifted Forward Arrow and Backward arrow, note
  1191.       blank space after <CSI>.
  1192.  
  1193.  
  1194.  
  1195.  
  1196.                               November 17, 1985
  1197.  
  1198.  
  1199.  
  1200.  
  1201.  
  1202.                                    - 19 -
  1203.  
  1204.  
  1205.           RAW             UNSHIFTED       SHIFTED
  1206.           KEY     KEYCAP  DEFAULT DEFAULT NUMBER  LEGEND  VALUE   VALUE
  1207.  
  1208.           50      F1      <CSI>0~ <CSI>10~
  1209.           51      F2      <CSI>1~ <CSI>11~
  1210.           52      F3      <CSI>2~ <CSI>12~
  1211.           53      F4      <CSI>3~ <CSI>13~
  1212.           54      F5      <CSI>4~ <CSI>14~
  1213.           55      F6      <CSI>5~ <CSI>15~
  1214.           56      F7      <CSI>6~ <CSI>16~
  1215.           57      F8      <CSI>7~ <CSI>17~
  1216.           58      F9      <CSI>8~ <CSI>18~
  1217.           59      F10     <CSI>9~ <CSI>19~
  1218.           5A              (undefined)       
  1219.           5B              (undefined)
  1220.           5C              (undefined)       
  1221.           5D              (undefined)
  1222.           5E              (undefined) 
  1223.           5F      HELP    <CSI>?~ <CSI>?~
  1224.  
  1225.  
  1226.  
  1227.  
  1228.  
  1229.  
  1230.  
  1231.  
  1232.  
  1233.  
  1234.  
  1235.  
  1236.  
  1237.  
  1238.  
  1239.  
  1240.  
  1241.  
  1242.  
  1243.  
  1244.  
  1245.  
  1246.  
  1247.  
  1248.  
  1249.  
  1250.  
  1251.  
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.  
  1259.                               November 17, 1985
  1260.  
  1261.  
  1262.  
  1263.  
  1264.  
  1265.                                    - 20 -
  1266.  
  1267.  
  1268.           KEY     KEYCAP NUMBER  LEGEND
  1269.  
  1270.           60      SHIFT (left of space bar)
  1271.           61      SHIFT (right of space bar)
  1272.           62      CAPS LOCK
  1273.           63      CTRL
  1274.           64      (Left) ALT 
  1275.           65      (Right) ALT
  1276.           66      Amiga   (left of space bar)       Close Amiga
  1277.           67      Amiga (right of space bar)      Open Amiga
  1278.           68      Left  mouse  button       Inputs  are  only  for  the
  1279.                      one (not converted)    mouse connected to Intuition 
  1280.           69      Right mouse button        currently "gameport"
  1281.                         one.                (not converted)
  1282.           6A      Middle mouse button           (not converted)
  1283.           6B      (undefined)  
  1284.           6C      (undefined)  
  1285.           6D      (undefined)
  1286.           6E      (undefined)  
  1287.           6F      (undefined)
  1288.  
  1289.  
  1290.  
  1291.  
  1292.  
  1293.  
  1294.  
  1295.  
  1296.  
  1297.  
  1298.  
  1299.  
  1300.  
  1301.  
  1302.  
  1303.  
  1304.  
  1305.  
  1306.  
  1307.  
  1308.  
  1309.  
  1310.  
  1311.  
  1312.  
  1313.  
  1314.  
  1315.  
  1316.  
  1317.  
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.                               November 17, 1985
  1325.  
  1326.  
  1327.  
  1328.  
  1329.  
  1330.                                    - 21 -
  1331.  
  1332.  
  1333.           center; l10 l.  RAW KEY NUMBER  FUNCTION
  1334.  
  1335.           70-7F   (undefined)
  1336.           80-F8   Up transition (release or unpress key of one
  1337.           of the above keys).  80 for 00, F8 for 7F.
  1338.           F9      Last keycode was bad           (was sent in order  to
  1339.                                                     resynchronize).
  1340.           FA      Keyboard buffer overflow.
  1341.           FB      (undefined, reserved for keyboard processor
  1342.                                             catastrophe)
  1343.           FC      Keyboard selftest failed.
  1344.           FD      Power-up key stream start.  Keys pressed or
  1345.                   stuck at power-up will be sent between FD and FE.
  1346.           FE      Power-up key stream end.
  1347.           FF      (undefined, reserved)
  1348.           FF      Mouse event, movement only, no button change.            
  1349.                   (not converted)
  1350.  
  1351.  
  1352.       Notes about the preceding table:
  1353.  
  1354.           1)  "(undefined)" indicates that the current keyboard  design
  1355.               should  not  generate this number.  If you are using Set-
  1356.               KeyMap() to change the key  map  the  entries  for  these
  1357.               numbers must still be included.
  1358.  
  1359.           2)  "(not converted)" refers to  mouse  button  events.   You
  1360.               must  use  the  sequence  "<CSI>2{" to inform the console
  1361.               driver that you wish to receive mouse  events;  otherwise
  1362.               these will not be transmitted.
  1363.  
  1364.           3)  "(RESERVED)" Indicates  that  these  keycodes  have  been
  1365.               reserved for non-US keyboards.  The "2B" code key will be
  1366.               between the double-quote(") and RETURN  keys.   The  "30"
  1367.               code key will be between the SHIFT and "Z" keys.
  1368.  
  1369.  
  1370.       1.8.  KEYMAPPING
  1371.  
  1372.       The Amiga has the capability  of  mapping  the  keyboard  in  any
  1373.       manner  that  you  wish.   In other computers, this capability is
  1374.       normally provided through the use of  "keyboard  enhancers".   In
  1375.       the  Amiga,  however,  the  capability is already present and the
  1376.       vectors that control the remapping are user accessible.
  1377.  
  1378.       The functions called GetKeyMap() and SetKeyMap() each deal with a
  1379.       set  of  8 longword pointers, known as the KeyMap data structure.
  1380.       The KeyMap data structure is shown below.
  1381.  
  1382.  
  1383.  
  1384.  
  1385.                               November 17, 1985
  1386.  
  1387.  
  1388.  
  1389.  
  1390.  
  1391.                                    - 22 -
  1392.  
  1393.  
  1394.  
  1395.                   struct KeyMap {
  1396.                       APTR km_LoKeyMapTypes;
  1397.                       APTR km_LoKeyMap;
  1398.                       APTR km_LoCapsable;
  1399.                       APTR km_LoRepeatable;
  1400.                       APTR km_HiKeyMapTypes;
  1401.                       APTR km_HiKeyMap;
  1402.                       APTR km_HiCapsable;
  1403.                       APTR km_HiRepeatable;
  1404.                       };
  1405.  
  1406.  
  1407.       GetKeyMap() returns a pointer to this table of pointers,  showing
  1408.       where  in  memory  each of the tables representing the keymapping
  1409.       may be found.
  1410.  
  1411.       As a prelude to the following material, note that the Amiga  key-
  1412.       board  transmits  raw key information to the computer in the form
  1413.       of a key position and a transition.  Figure 4-1 shows a  physical
  1414.       layout of the keys and the hexadecimal number that is transmitted
  1415.       to the system when a key is pressed.  When the key  is  released,
  1416.       its  value,  plus hexadecimal 80, is transmitted to the computer.
  1417.       The key mapping described herein refers to the  translation  from
  1418.       this raw key transmission into console device output to the user.
  1419.  
  1420.       The low key map provides translation of the key values  from  hex
  1421.       00-3F;  the  high  key map provides translation of key value from
  1422.       hex 40-67.
  1423.  
  1424.       Raw output from the keyboard for the LoKeyMap  does  not  include
  1425.       the  space bar, TAB, ALT, CTRL, arrow keys and several other keys
  1426.       (shown in HiKeyMap, below).
  1427.  
  1428.  
  1429.  
  1430.  
  1431.  
  1432.  
  1433.  
  1434.  
  1435.  
  1436.  
  1437.  
  1438.  
  1439.  
  1440.  
  1441.  
  1442.  
  1443.  
  1444.  
  1445.  
  1446.                   Figure 1-2: Low Key Map Translation Table
  1447.  
  1448.  
  1449.  
  1450.  
  1451.                               November 17, 1985
  1452.  
  1453.  
  1454.  
  1455.  
  1456.  
  1457.                                    - 23 -
  1458.  
  1459.  
  1460.  
  1461.                      Table 1-6: High Key Map Hex Values
  1462.  
  1463.  
  1464.     40      Space   
  1465.     41      Backspace    
  1466.     42      Tab    
  1467.     43      Enter
  1468.     44      Return  
  1469.     45      Escape 
  1470.     46      Delete 
  1471.     4A      Numeric Pad
  1472.     4C      Cursor Up 
  1473.     4D      Cursor  Down  
  1474.     4E      Cursor  Forward
  1475.     4F      Cursor Backward 
  1476.     50-59   Function keys F1-F10 
  1477.     5F      Help
  1478.     60      Left  Shift   
  1479.     61      Right   Shift   
  1480.     62      Caps   Lock
  1481.     63      Control  
  1482.     64      Left  Alt 
  1483.     65      Right Alt 
  1484.     66      Left Amiga 
  1485.     67      Right Amiga
  1486.  
  1487.  
  1488.       The keymap table for the low and high keymaps consists of  4-byte
  1489.       entries,  one  per hex keycode.  These entries are interpreted in
  1490.       one of two possible ways:
  1491.  
  1492.           a.  as 4 separate bytes, specifying how  the  key  is  to  be
  1493.               interpreted when pressed:
  1494.  
  1495.               o   alone
  1496.  
  1497.               o   with one qualifier
  1498.  
  1499.               o   with another qualifier
  1500.  
  1501.               o   with both qualifiers
  1502.               where a qualifier is one of three possible keys:
  1503.  
  1504.               o   CTRL (control)
  1505.  
  1506.               o   ALT
  1507.  
  1508.               o   SHIFT
  1509.  
  1510.           b.  as a longword containing the address of a string descrip-
  1511.               tor,  where  a  string of hex digits is to be output when
  1512.               this key is pressed.  If a string is to  be  output,  any
  1513.               combination  of qualifiers may affect the string that may
  1514.               be transmitted.
  1515.  
  1516.       NOTE:   The keymap table must begin aligned on a  word  boundary.
  1517.       Each  entry  is  4-bytes long, thereby maintaining word alignment
  1518.       throughout the table.   This  is  necessary  since  some  of  the
  1519.       entries  may  be  longword addresses and must be aligned properly
  1520.       for the 68000.
  1521.  
  1522.  
  1523.       As you may have noticed, there are three possible qualifiers, but
  1524.       only  a  4-byte  space  in the table for each key.  This does not
  1525.       allow space to describe what the computer should output  for  all
  1526.       possible  combinations  of qualifiers.  This problem is solved by
  1527.  
  1528.  
  1529.  
  1530.                               November 17, 1985
  1531.  
  1532.  
  1533.  
  1534.  
  1535.  
  1536.                                    - 24 -
  1537.  
  1538.  
  1539.       only allowing all three qualifiers to affect the  output  at  the
  1540.       same time in string mode.  Here is how that works.
  1541.  
  1542.       For "vanilla" keys, such as the alphabetic keys, use the 4  bytes
  1543.       to  represent  the  data  output  for the key alone, shifted key,
  1544.       ALT'ed key, and shifted-and-ALT'ed key.  Then for  the  CTRL-key-
  1545.       plus-vanilla-key,  use the code for the key alone with bits 6 and
  1546.       5 set to 0.
  1547.  
  1548.       For other keys, such as the return key or escape key, the qualif-
  1549.       iers  specified in the keytypes table (up to two) are the qualif-
  1550.       iers used to establish the response to the key.  This is done  as
  1551.       follows.   In  the  keytypes table, the values listed for the key
  1552.       types are  those  listed  for  the  qualifiers  in  keymap.h  and
  1553.       keymap.i.  Specifically, these qualifier equates are:
  1554.  
  1555.  
  1556.                     KC_NOQUAL       0x00    
  1557.                     KCF_SHIFT       0x01
  1558.                     KCF_ALT         0x02       
  1559.                     KCF_CONTROL     0x04      
  1560.                     KC_VANILLA      0x07
  1561.                     KCF_DOWNUP      0x08 
  1562.                     KCF_STRING      0x40
  1563.  
  1564.  
  1565.  
  1566.       As shown above, the qualifiers for  the  various  types  of  keys
  1567.       occupy specific bit positions in the key types control byte.
  1568.  
  1569.       A keymap table entry looks like this, in assembly code:
  1570.  
  1571.               SOME_KEY:
  1572.                   DC.B    VALUE_1, VALUE_2, VALUE_3, VALUE_4
  1573.  
  1574.  
  1575.       Here is how you interpret the keymap for various combinations  of
  1576.       the qualifier bits:
  1577.  
  1578.  
  1579.  
  1580.  
  1581.  
  1582.  
  1583.  
  1584.  
  1585.  
  1586.  
  1587.  
  1588.  
  1589.  
  1590.  
  1591.  
  1592.  
  1593.  
  1594.  
  1595.  
  1596.  
  1597.  
  1598.  
  1599.  
  1600.                               November 17, 1985
  1601.  
  1602.  
  1603.  
  1604.  
  1605.  
  1606.                                    - 25 -
  1607.  
  1608.  
  1609.  
  1610.                       Table 1-7: Keymap Qualifier Bits
  1611.  
  1612.  
  1613.     If  Keytype is:   Then value in this position in the         
  1614.                         keytable is out put when the key is         
  1615.                         pressed along with:
  1616.  
  1617.     KC_NOQUAL       -       -       -       alone   
  1618.     KCF_SHIFT       -       -       SHIFT   alone                    
  1619.     KCF_ALT -       -       ALT     alone                    
  1620.     KCF_CONTROL     -       -       CTRL    alone
  1621.     KCF_ALT+KCF_SHIFT       SHIFT+ALT       ALT     SHIFT   alone
  1622.     KCF_CONTROL+KCF_ALT     CTRL+ALT        CTRL    ALT     alone
  1623.     KCF_CONTROL+KCF_SHIFT   CTRL+SHIFT      CTRL    SHIFT   alone
  1624.     KC_VANILLA      SHIFT+ALT       ALT     SHIFT   alone*
  1625.  
  1626.  
  1627.           *   special case-CTRL key, when pressed with one of  the  al-
  1628.               phabet  keys  and  certain others, is to output key-alone
  1629.               value with the bits 6 and 5 set to zero.
  1630.  
  1631.  
  1632.       The vectors named km_LoKeyTypes  and  km_HiKeyTypes  contain  one
  1633.       byte  per raw key code.  This byte defines the entry type that is
  1634.       made in the key table by a set of bit positions.
  1635.  
  1636.       Possible key types are:
  1637.  
  1638.           o   any of the qualifier groupings noted above, or
  1639.  
  1640.  
  1641.           o   KCF_STRING +   any  combination  of  KCF_SHIFT,  KCF_ALT,
  1642.               KCF_CONTROL  (or KC_NOQUAL) if the result of pressing the
  1643.               key is to be a  stream  of  bytes  (and  key-with-one-or-
  1644.               more-qualifiers is to be one or more alternate streams of
  1645.               bytes).
  1646.               Any key can be made to output up to 8 unique byte streams
  1647.               if KCF_STRING is set in its keytype.  The only limitation
  1648.               is that the total length of all of the  strings  assigned
  1649.               to  a  key  be  within  the "jump range" of a single byte
  1650.               increment.  See the "String-Output  Keys"  section  below
  1651.               for more information.
  1652.  
  1653.       The low keytype table covers the raw keycodes from hex 00-3F, and
  1654.       contains  one byte per keycode.  Therefore this table contains 64
  1655.       (decimal) bytes.  The high keytype table covers the raw  keycodes
  1656.       from hex 40-67, and contains 38 (decimal) bytes.
  1657.  
  1658.  
  1659.       When a key is to output a string, the keymap table  contains  the
  1660.       address  of a string descriptor in place of a 4-byte mapping of a
  1661.       key as shown above.  Here is a partial table for a new  high  key
  1662.       map  table which contains only three entries thus far.  The first
  1663.  
  1664.  
  1665.                               November 17, 1985
  1666.  
  1667.  
  1668.  
  1669.  
  1670.  
  1671.                                    - 26 -
  1672.  
  1673.  
  1674.       two are for the space bar and the backspace key; the third is for
  1675.       the  tab  key, which is to output a string that says "[TAB]".  An
  1676.       alternate string, "[SHIFTED-TAB]", is also to be  output  when  a
  1677.       shifted TAB key is pressed.
  1678.  
  1679.                   Table 1-8: Composing an Alternate Key Map
  1680.  
  1681.  
  1682.       newHiMapTypes:
  1683.           DC.B        KCF_ALT,KC_NOQUAL,
  1684.           DC.B        KCF_STRING+KCF_SHIFT,         ...     ;(more)
  1685.       newHiMap:
  1686.           DC.B        0,0,$A0,$20     ;space bar, and ALT-space bar
  1687.           DC.B        0,0,0,$08       ;BACKSPACE key only
  1688.           DC.L        newkey42        ;new  definition  for  string  to
  1689.                       ;output for TAB key         ...     ;(more)
  1690.       newkey42:
  1691.           DC.B        new42ue   -    new42us       ;length    of    the
  1692.                       ;unshifted string
  1693.           DC.B        new42us  -  newkey42                  
  1694.                         ;number of bytes from start of                 
  1695.                         ;string descriptor to start of                 
  1696.                         ;this string
  1697.           DC.B        new42se - new42ss   ;length of  the shifted string
  1698.           DC.B        new42ss  -  newkey42                  
  1699.                         ;number of bytes  from  start of                 
  1700.                         ;string descriptor to start of                 
  1701.                         ;this string
  1702.       new42us:
  1703.           DC.B        '[TAB]'
  1704.       new42ue:
  1705.       new42ss:
  1706.           DC.B        '[SHIFTED-TAB]'
  1707.       new42se:
  1708.  
  1709.  
  1710.       The new high map table points to the string descriptor at address
  1711.       newkey42.   The  new  high map types table says that there is one
  1712.       qualifier, which means that there are  two  strings  in  the  key
  1713.       string descriptor.
  1714.  
  1715.       Each string in the descriptor takes two bytes in this part of the
  1716.       table;  the  first  byte  is the length of the string, the second
  1717.       byte is the distance from the start  of  the  descriptor  to  the
  1718.       start  of  the  string.  Therefore, a single string (KCF_STRING +
  1719.       KC_NOQUAL) takes 2 bytes of string descriptor.  If there  is  one
  1720.       qualifier,  4  bytes  of  descriptor  are used.  If there are two
  1721.       qualifiers, 8 bytes of descriptor are used.  If there are 3 qual-
  1722.       ifiers,  16  bytes  of  descriptor  are  used.  All strings start
  1723.       immediately following the string  descriptor  in  that  they  are
  1724.  
  1725.  
  1726.                               November 17, 1985
  1727.  
  1728.  
  1729.  
  1730.  
  1731.  
  1732.                                    - 27 -
  1733.  
  1734.  
  1735.       accessed  as single byte offsets from the start of the descriptor
  1736.       itself.  Therefore, the distance from the start of the descriptor
  1737.       to  the  last string in the set (the one that uses the entire set
  1738.       of specified qualifiers) must  start  within  255  bytes  of  the
  1739.       descriptor address.
  1740.  
  1741.       Since the length of the string is contained in a single byte, the
  1742.       length  of any single string must be 255 bytes or less while also
  1743.       meeting the "reach" requirement.
  1744.  
  1745.       The length of a keymap containing string descriptors and  strings
  1746.       is  variable  and  depends  on the number and size of the strings
  1747.       that you provide.
  1748.  
  1749.  
  1750.       The vectors called km_LoCapsable and km_HiCapsable point  to  the
  1751.       first  byte  in  an  8-byte  table that contains more information
  1752.       about the keytable entries.
  1753.  
  1754.       Specifically, if the CAPS LOCK key has been pressed the CAPS LOCK
  1755.       LED  is  on),  and  if  there is a bit on in that position in the
  1756.       capsable map, then this key will be treated as though the  shift-
  1757.       key  is  now  currently  pressed. For example, in the default key
  1758.       mapping, the alphabetic keys are "capsable" but  the  punctuation
  1759.       keys  are not.  This allows you to set the shift-lock, just as on
  1760.       a normal typewriter,  and  get  all  capital  letters.   However,
  1761.       unlike  a normal typewriter, you need not go out of shift-lock to
  1762.       correctly type the punctuation symbols or numeric keys.
  1763.  
  1764.       In the table, the bits that control  this  feature  are  numbered
  1765.       from  the lowest bit in the byte, and from the lowest memory byte
  1766.       address to the highest.  For example, the bit representing  caps-
  1767.       able  status  for  the key that transmits raw code 00 is bit 0 in
  1768.       byte 0; for the key that transmits raw code 08 it's bit 0 in byte
  1769.       1,  and so on.
  1770.  
  1771.       There are 64 bits (8-bytes) in each of the two capsable tables.
  1772.  
  1773.  
  1774.       For both the low and high key maps there is an 8-byte table  that
  1775.       provides  one  bit per possible raw key code.  This bit indicates
  1776.       whether or not the specified key should repeat at the rate set by
  1777.       the  Preferences  program.  The bit positions correspond to those
  1778.       specified in the capsable bit table.
  1779.  
  1780.       If there is a 1 in a specific position, the key can repeat.   The
  1781.       vectors that point to these tables are called km_LoRepeatable and
  1782.       km_HiRepeatable.
  1783.  
  1784.  
  1785.       In the default low key map, all of the keys are  treated  in  the
  1786.       same manner.  That is:
  1787.  
  1788.           o   When pressed alone, they transmit the ASCII equivalent of
  1789.  
  1790.  
  1791.  
  1792.                               November 17, 1985
  1793.  
  1794.  
  1795.  
  1796.  
  1797.  
  1798.                                    - 28 -
  1799.  
  1800.  
  1801.               the unshifted key.
  1802.  
  1803.  
  1804.           o   When shifted, they translate the ASCII equivalent of  the
  1805.               shifted value when printed on the keycap.
  1806.  
  1807.  
  1808.           o   When "ALT'ed" (pressed  along  with  an  ALT  key),  they
  1809.               transmit  the alone-value with the high bit of a byte set
  1810.               (value plus hex 80).
  1811.  
  1812.  
  1813.               When shifted and ALT'ed, they transmit the  shifted-value
  1814.               plus hex 80.
  1815.  
  1816.       In this table, the bytes that describe the data to be transmitted
  1817.       are positioned as the example for the "A" key shown here:
  1818.  
  1819.       center; l l l  l.   
  1820.     key_A   DC.B    ('A')+$80       ;shifted and ALT'ed                
  1821.             DC.B    ('a')+$80       ;ALT'ed only
  1822.             DC.B    ('A')   ;shifted only
  1823.             DC.B    ('a')   ;not shifted or ALT'ed.
  1824.  
  1825.  
  1826.       In addition to the response to the key alone, shifted, ALT'ed and
  1827.       shifted-and-ALT'ed,  the  default low keymap also responds to the
  1828.       key combination of "CTRL + key" by stripping off bits 6 and 5  of
  1829.       the  generated  data  byte.   For example, CTRL + A generates the
  1830.       translated keycode 01 (61 with bits 6 and 5 set to 0).
  1831.  
  1832.       All keys in the low key map are mapped to their ASCII equivalents
  1833.       as noted in the low key map key table shown above.
  1834.  
  1835.       Since the low key table contains 4 bytes per key,  and  describes
  1836.       the  keys (raw codes) from hex 00-3F, there are 64 times 4 or 256
  1837.       bytes in this table.
  1838.  
  1839.  
  1840.       Most of the keys in the high key map generate strings rather than
  1841.       single  character mapping. The following keys map characters with
  1842.       no qualifier, along with their byte mapping:
  1843.  
  1844.  
  1845.  
  1846.       KEY     GENERATES VALUE:
  1847.  
  1848.       BACKSP  $08 ENTER   $0D DEL     $7F
  1849.  
  1850.  
  1851.  
  1852.  
  1853.  
  1854.  
  1855.                               November 17, 1985
  1856.  
  1857.  
  1858.  
  1859.  
  1860.  
  1861.                                    - 29 -
  1862.  
  1863.  
  1864.       The following keys map characters and use a single qualifier:
  1865.  
  1866.  
  1867.  
  1868.       KEY     GENERATES   VALUE:        IF   USED    WITH    QUALIFIER,
  1869.                       GENERATES VALUE:
  1870.  
  1871.     SPACE   $20     $A0 (qualifier = ALT) 
  1872.     RETURN  $0D     $0A  (qualifier = CONTROL) 
  1873.     ESC     $1B     $9B (qualifier = ALT)
  1874.     numeric pad '-' $2D     $FF (qualifier = ALT)
  1875.  
  1876.  
  1877.  
  1878.  
  1879.       The following keys generate strings:
  1880.  
  1881.  
  1882.  
  1883.       KEY     GENERATES    VALUE:        IF    USED    WITH    <SHIFT>,
  1884.                       GENERATES VALUE:
  1885.  
  1886.     TAB   $09     $9B, followed by 'Z'
  1887.  
  1888.     cursor:
  1889.     UP    $9B, followed by 'A'    $9B, followed by 'T'
  1890.     DOWN  $9B, followed by 'B'    $9B, followed by 'S'
  1891.     FWD   $9B,  followed  by   'C'    $9B,   followed   by   '   ',
  1892.                 followed by '@'
  1893.     BACKWD  $9B, followed by 'D'    $9B,  followed  by  '  ',
  1894.                 followed by 'A'
  1895.  
  1896.       function keys:
  1897.         F1    $9B, followed by '0~'   $9B, followed by '10~'
  1898.         F2    $9B, followed by '1~'   $9B, followed by '11~'
  1899.         F3    $9B, followed by '2~'   $9B, followed by '12~'
  1900.         F4    $9B, followed by '3~'   $9B, followed by '13~'
  1901.         F5    $9B, followed by '4~'   $9B, followed by '14~'
  1902.         F6    $9B, followed by '5~'   $9B, followed by '15~'
  1903.         F7    $9B, followed by '6~'   $9B, followed by '16~'
  1904.         F8    $9B, followed by '7~'   $9B, followed by '17~'
  1905.         F9    $9B, followed by '8~'   $9B, followed by '18~'
  1906.         F10   $9B, followed by '9~'   $9B, followed by '19~'
  1907.  
  1908.       HELP    $9B, followed by '?~'   (no qualifier used)
  1909.  
  1910.  
  1911.  
  1912.  
  1913.                               November 17, 1985
  1914.  
  1915.  
  1916.  
  1917.  
  1918.  
  1919.                                    - 30 -
  1920.  
  1921.  
  1922.       1.9.  CLOSING A CONSOLE DEVICE
  1923.  
  1924.       When you have finished using a console, it must be closed so that
  1925.       the memory areas it utilized may be returned to the system memory
  1926.       manager.  Here is a sequence that you can use to close a  console
  1927.       device:
  1928.  
  1929.               CloseDevice(requestBlock);
  1930.  
  1931.  
  1932.       Note that you should also delete the messages and  ports  associ-
  1933.       ated with this console after the console has been closed:
  1934.  
  1935.               DeleteStdIO(consoleWriteMsg);
  1936.               DeleteStdIO(consoleReadMsg);
  1937.               DeletePort(consoleWritePort);
  1938.               DeletePort(consoleReadPort);
  1939.  
  1940.  
  1941.       If you have finished with the window used for the console device,
  1942.       you can now close it.
  1943.  
  1944.  
  1945.  
  1946.  
  1947.  
  1948.  
  1949.  
  1950.  
  1951.  
  1952.  
  1953.  
  1954.  
  1955.  
  1956.  
  1957.  
  1958.  
  1959.  
  1960.  
  1961.  
  1962.  
  1963.  
  1964.  
  1965.  
  1966.  
  1967.  
  1968.  
  1969.  
  1970.  
  1971.  
  1972.  
  1973.  
  1974.  
  1975.  
  1976.  
  1977.  
  1978.                               November 17, 1985
  1979.